import socket
import struct
import random
import time

def send_neighbor_solicitation(interface, target_ip):
    # Create an IPv6 UDP socket
    sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)

    # Prepare IPv6 neighbor solicitation
    ipv6_header = b'\x60\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'
    neighbor_solicitation = b'\x88\x00\x00\x00' + b'\x00' * 12

    # Assemble IPv6 packet
    packet = ipv6_header + neighbor_solicitation

    # Send neighbor solicitation to the target IPv6 address
    while True:
        sock.sendto(packet, (target_ip, 0, 0, interface))
        print("Sending IPv6 Neighbor Solicitation to", target_ip)
        time.sleep(0.1)  # Control the sending rate

if __name__ == "__main__":
    try:
        # Get user input for the network interface name and target IPv6 address
        interface = input("Please enter the network interface name: ")
        target_ip = input("Please enter the target IPv6 address: ")

        # Send neighbor solicitation
        send_neighbor_solicitation(interface, target_ip)
    except KeyboardInterrupt:
        print("\033[1;31;40m[*] User interrupted the program")
        print("\033[1;37;40m")
    except Exception as e:
        print("\033[1;31;40m[*] An error occurred:", e)
        print("\033[1;37;40m")
